package com.petecat.interchan.base.param.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.petecat.interchan.base.param.service.IParamService;
import com.petecat.interchan.core.constans.Global;
import com.petecat.interchan.core.controller.BaseController;
import com.petecat.interchan.protocol.GlobalHeader;
import com.petecat.interchan.protocol.Result;
import com.petecat.interchan.protocol.base.param.dto.BsPropertiesAddDTO;
import com.petecat.interchan.protocol.base.param.dto.BsPropertiesQryDTO;
import com.petecat.interchan.protocol.base.param.dto.BsPropertiesUpdDTO;
import com.petecat.interchan.protocol.base.param.vo.BsPropertiesQryVO;
import com.petecat.interchan.protocol.data.PageVO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@Api("参数配置管理")
@RequestMapping("/base/param")
public class ParamController extends BaseController{
		
	@Autowired
	private IParamService paramService;
	//
	@SuppressWarnings("unchecked")
	@ApiOperation("分页查询参数配置信息")
	@GetMapping("/queryParamByPage")
	public Result<PageVO<BsPropertiesQryVO>> queryParamByPage(@ModelAttribute BsPropertiesQryDTO bsPropertiesQryDTO,
			@ApiIgnore @RequestHeader(name = Global.GLOBAL_HEADER, required = false) String header) {
		GlobalHeader userInfo = this.getUserInfo(header, true);
		bsPropertiesQryDTO.setUserId(userInfo.getUserId());
		PageVO<BsPropertiesQryVO> pageVO = paramService.queryParamByPage(bsPropertiesQryDTO);
		return (Result<PageVO<BsPropertiesQryVO>>) Result.ok(pageVO);
	}
	

	@ApiOperation(value = "新增参数配置基本信息", notes = "新增")
	@PostMapping(value = "/saveParam")
	public Result<?> saveParam(@RequestBody BsPropertiesAddDTO bsPropertiesAddDTO,
			@ApiIgnore @RequestHeader(name = Global.GLOBAL_HEADER, required = false) String header) {
		GlobalHeader userInfo = this.getUserInfo(header, true);
		paramService.saveParam(bsPropertiesAddDTO, userInfo.getUserId());
		return Result.ok();
	}

	@ApiOperation("修改参数配置状态")
	@DeleteMapping("/updateParamById")
	public Result<?> updateParamById(@RequestParam String paramId,@RequestParam String projectId,@RequestParam String state,
			@ApiIgnore @RequestHeader(name = Global.GLOBAL_HEADER, required = false) String header) {
		paramService.deleteParamById(paramId,projectId,state);
		return Result.ok();
	}
	
	@ApiOperation("删除参数配置")
	@DeleteMapping("/removeParamById")
	public Result<?> removeParamById(@RequestParam String paramId,
			@ApiIgnore @RequestHeader(name = Global.GLOBAL_HEADER, required = false) String header) {
		paramService.removeParamById(paramId);
		return Result.ok();
	}

	@ApiOperation("修改参数配置基本信息")
	@PutMapping("/modifyParamById")
	public Result<?> modifyParamById(@RequestBody BsPropertiesUpdDTO bsPropertiesUpdDTO,
			@ApiIgnore @RequestHeader(name = Global.GLOBAL_HEADER, required = false) String header) {
		GlobalHeader userInfo = this.getUserInfo(header, true);
		paramService.modifyParamById(bsPropertiesUpdDTO, userInfo.getUserId());
		return Result.ok();
	}
	
	
}
